package com.itheima.ticket.ticket05;

import java.util.concurrent.atomic.AtomicInteger;

public class Ticket implements Runnable{
  private volatile AtomicInteger ticket=new AtomicInteger(100);

    @Override
    public void run() {
       while (true){
           //人有操作  耗时间
           if(ticket.get()>0){
               try {
                   Thread.sleep(10);
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }

               System.out.println(Thread.currentThread().getName()+"正在卖"+ticket+"张票");
               ticket.decrementAndGet();
           }else {
               break;
           }

       }
    }
}
